package com.awenhui.demo.core.base;

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * HTTP响应接口输出参数模型定义类
 * 
 * @author yuxf
 */
@Data
public class ActionResult<T>   implements Serializable {

    private static final long serialVersionUID = 1L;

    @JsonInclude
    @ApiModelProperty(value = "返回码")
    private int code;

    @JsonInclude
    @ApiModelProperty(value = "请求成功标识")
    private boolean success;

    @JsonInclude(value = Include.NON_NULL)
    @ApiModelProperty(value = "返回信息")
    private String message;

    @JsonInclude(value = Include.NON_NULL)
    @ApiModelProperty(value = "返回数据")
    private T data;

    public ActionResult() {
    }

    /**
     * 构造方法
     *
     * @param resultCode 响应代码
     */
    public ActionResult(IBaseEnum resultCode) {
        this.setSuccess(resultCode.getValue() == 0);
        this.setCode(resultCode.getValue());
        this.setMessage(resultCode.getDescription());
        this.setData(null);
    }

    /**
     * 构造方法
     *
     * @param resultCode 响应代码
     * @param data       响应数据
     */
    public ActionResult(IBaseEnum resultCode, T data) {
        this.setSuccess(resultCode.getValue() == 0);
        this.setCode(resultCode.getValue());
        this.setMessage(resultCode.getDescription());
        this.setData(data);
    }

    /**
     * 构造方法
     *
     * @param code 响应代码
     * @param data 响应数据
     */
    public ActionResult(int code, T data) {
        this.setSuccess(code == 0);
        this.setCode(code);
        this.setData(data);
        this.setMessage(null);
    }

    /**
     * 构造方法
     *
     * @param code    响应代码
     * @param message 错误信息
     */
    public ActionResult(int code, String message) {
        this.setSuccess(code == 0);
        this.setCode(code);
        this.setData(null);
        this.setMessage(message);
    }

    /**
     * 构造方法
     *
     * @param code    响应代码
     * @param message 响应消息
     * @param data    响应数据
     */
    public ActionResult(int code, String message, T data) {
        this.setSuccess(code == 0);
        this.setCode(code);
        this.setData(data);
        this.setMessage(message);
    }

  

}
